package com.tchhy.provider.rx

import io.reactivex.*
import org.reactivestreams.Publisher

/**
 *
 * Describe: RxJava线程戏切换相关
 *
 * Author: wfy
 *
 */
open class BaseScheduler<T>(private val subscriberOnScheduler: Scheduler, private val observerOnScheduler: Scheduler) :
        ObservableTransformer<T, T>,
        FlowableTransformer<T, T>,
        SingleTransformer<T, T>,
        MaybeTransformer<T, T>,
        CompletableTransformer {

    override fun apply(upstream: Observable<T>): ObservableSource<T> {
        return upstream.observeOn(observerOnScheduler)
                .subscribeOn(subscriberOnScheduler)
    }

    override fun apply(upstream: Flowable<T>): Publisher<T> {
        return upstream.observeOn(observerOnScheduler)
                .subscribeOn(subscriberOnScheduler)
    }

    override fun apply(upstream: Single<T>): SingleSource<T> {
        return upstream.observeOn(observerOnScheduler)
                .subscribeOn(subscriberOnScheduler)
    }

    override fun apply(upstream: Maybe<T>): MaybeSource<T> {
        return upstream.observeOn(observerOnScheduler)
                .subscribeOn(subscriberOnScheduler)
    }

    override fun apply(upstream: Completable): CompletableSource {
        return upstream.observeOn(observerOnScheduler)
                .subscribeOn(subscriberOnScheduler)
    }
}